package com.dengbw.systemtransfer.service;

import com.dengbw.systemtransfer.mapper.CmmFunctionExtConfigMapper;
import com.dengbw.systemtransfer.model.function.CmmExtTask;
import com.dengbw.systemtransfer.model.function.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author dengbw
 * @date 2021/11/11 2:31 下午
 */
@Service
public class CmmFunctionExtConfigService {

    CmmFunctionExtConfigMapper cmmFunctionExtConfigMapper;

    @Autowired
    public CmmFunctionExtConfigService(CmmFunctionExtConfigMapper cmmFunctionExtConfigMapper) {
        this.cmmFunctionExtConfigMapper = cmmFunctionExtConfigMapper;
    }


    @Transactional(rollbackFor = Exception.class)
    public void saveExtConfig(String zhenCorpId, Long cunSubId, Map<String, String> core) {
        for (CmmExtTask t : Task.extTask(zhenCorpId, core)) {
            cmmFunctionExtConfigMapper.save(t.getId(), t.getName(), t.getType(), t.getUrl(), t.getCorpId(), t.getPlatform(), cunSubId);
        }
    }
}
